<?php

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use app\common\model\User;

class ShowUsers extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('user:showusers')
            ->setDescription('显示所有用户');
        // 设置参数

    }

    protected function execute(Input $input, Output $output)
    {
    	// 指令输出
        $output->writeln("用户名\t密码\t真实姓名\t注册时间\t上次登录时间");
        $output->writeln(str_repeat('-', 60));
        $users = User::where(1)->select();
        foreach ($users as $user) {
            /** @var User $user */
            $line = $user->username . "\t"
                . substr($user->password, 0, 6) . "...\t"
                . $user->realname . "\t"
                . $user->register_at . "\t"
                . $user->last_login_at;
            $output->writeln($line);
        }
        $output->writeln(str_repeat('-', 60));
    }
}
